﻿using System.Linq;
using System.Windows;
using System.Windows.Media;
using ConfApp.Models;
using ConfApp.Services;

namespace ConfApp.ViewModels
{
    public class TrackInfoViewModel : ViewModel 
    {
        private readonly Track _track;
        
        public TrackInfoViewModel(
            Track track, 
            INavigationService navigationService)
            : base(navigationService)
        {
            _track = track;
        }

        public Track Track
        {
            get { return _track; }
        }

        public int ID { get { return _track.ID; } }
        public string Title { get { return _track.Title; } }
        public string Code { get { return _track.Code; } }

        public string Info { get { return _track.ID==-1? _track.Title : string.Format("{0} ({1})", Title, Code); } }

        public Brush Color { get { return new SolidColorBrush(HandleWhiteColor(_track.Color)); } }

        private Color HandleWhiteColor(Color color)
        {
            if (LightThemeEnabled)
            {
                if (color == Colors.White)
                {
                    return Colors.Black;
                }
            }
            else
            {
                if (color == Colors.Black)
                {
                    return Colors.White;
                }
            }
            return color;
        }

        public bool LightThemeEnabled
        {
            get
            {
                return (Visibility)Application.Current.Resources["PhoneLightThemeVisibility"] == Visibility.Visible;
            }
        }

        public override void IsBeingActivated()
        {

        }
    }
}
